// pages/consulting/consulting.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    name:'',
    phone:0,
    address:'',
    content:''
  },
  toserviceagreement:function(){
    wx.navigateTo({
      url: "../serviceagreement/serviceagreement",
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },

  getName: function (e){
    var name = e.detail.value;
    this.setData({
      name: name
    });
  },

  getPhone: function (e) {
    var phone = e.detail.value;
    this.setData({
      phone: phone
    });
  },

  getAddress: function (e) {
    var address = e.detail.value;
    this.setData({
      address: address
    });
  },

  getContent: function (e) {
    var content = e.detail.value;
    this.setData({
      content: content
    });
  },

  send:function () {
    var that = this;
    var name = that.data.name;
    var phone = that.data.phone;
    var address = that.data.address;
    var content = that.data.content;
    if(!name){
      wx.showToast({
        title: '请输入姓名！',
      });
      return false;
    };
    if (!phone) {
      wx.showToast({
        title: '请输入手机号！',
      });
      return false;
    };
    if (!address) {
      wx.showToast({
        title: '请输入意向地址！',
      });
      return false;
    };
    wx.request({
      url: app.d.ceshiUrl + '/Api/User/comment',
      method: 'post',
      data: {
        uid: app.d.userId,
        name: name,
        phone:phone,
        address:address,
        content:content
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        if (res.data.status == 1) {
          wx.showToast({
            title: res.data.err,
            duration:2000
          });
          setTimeout(function(){
            wx.navigateBack({
              
            })
          },2000);
        } else {
          wx.showToast({
            title: res.data.err,
          })
        }

        //endInitData
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 2000
        });
      },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})